package me.yangzhi.demo;

import android.os.Bundle;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ListView lvMessages;
    private List<Friend> friends;
    private FriendAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 初始化视图
        lvMessages = findViewById(R.id.lv_messages);

        // 初始化数据
        friends = new ArrayList<>();
        friends.add(new Friend("张三", R.mipmap.ic_launcher_round));
        friends.add(new Friend("李四", R.mipmap.ic_launcher_round));
        friends.add(new Friend("王五", R.mipmap.ic_launcher_round));

        // 设置适配器
        adapter = new FriendAdapter(this, friends);
        lvMessages.setAdapter(adapter);
    }
}